<template>
  <div class="page-article bg-grey-2" v-if="ArticleDetails">
    <div class="d-flex ai-center px-1 border-bottom jc-between" style="height:.32rem">
      <i class="icon iconfont" @click="back">&#xe511;</i>
      <div class="flex-grow-1 px-1 fs-sm text-title text-ellipsis">{{ArticleDetails.title}}</div>
      <div
        class="text-grey fs-sm"
        style="width:.85rem; text-align:right;"
      >{{ArticleDetails.createdAt | date}}</div>
    </div>
    <div v-html="ArticleDetails.body" class="px-3 bg-grey-2 body fs-xl"></div>
    <div class="px-3 border-top py-3">
      <div class="d-flex ai-center">
        <i class="iconfont icon-menu1"></i>
        <strong class="text-blue fs-lg ml-1">相关资讯</strong>
      </div>
      <div class="pt-2">
        <router-link
          class="py-1 fs-sm text-ellipsis"
          tag="div"
          :to="`/articles/${item.id}`"
          v-for="item in Related"
          :key="item.id"
        >{{item.title}}</router-link>
      </div>
    </div>
  </div>
</template>

<script>
import dayjs from "dayjs";
export default {
  filters: {
    date(val) {
      return dayjs(val).format("YYYY-MM-DD");
    }
  },
  props: {
    id: { required: true }
  },
  data() {
    return {
      ArticleDetails: [],
      Related: []
    };
  },
  watch: {
    id: "fetchArticleDetails"
    // id(){
    //   this.fetch()
    // }
  },
  methods: {
    back(){
      this.$router.go(-1)
    },
    async fetchArticleDetails() {
      const res = await this.$http.get(`articles/Details/${this.id}`);
      this.ArticleDetails = res.data.data;
      this.Related = res.data.data2;
    }
  },
  created() {
    this.fetchArticleDetails();
  }
};
</script>

<style lang="scss">
.page-article {
  .body {
    img {
      max-width: 100%;
      height: auto;
    }
    iframe {
      width: 100%;
      height: auto;
    }
    p {
      margin: 0px;
      font-size: 0.13rem;
    }
  }
}
</style>

